import java.util.concurrent.locks.ReentrantLock;
class Count {
    public int count = 0;

     public void increase() {
        count++;
    }
}
    public class Demo8 {
            public static void main(String[] args) throws InterruptedException {
                Count counter = new Count();
                ReentrantLock locker=new ReentrantLock();
                Thread t1 = new Thread(() -> {

                    locker.lock();
                    for (int i = 0; i < 5000; i++) {
                        counter.increase();
                    }
                    locker.unlock();
                });
                Thread t2 = new Thread(() -> {
                    ReentrantLock lock=new ReentrantLock();
                    locker.lock();
                    for (int i = 0; i < 5000; i++) {
                        counter.increase();
                    }
                    locker.unlock();
                });
                t1.start();
                t2.start();

                t1.join();       //等待t1执行完毕，之前上一个没写join,但是就算写他也是错的
                t2.join();       //等待t2执行完毕，最后main线程

                System.out.println(counter.count);
            }
        }
